//
//  VCViewModel.m
//  TestForReactiveCocoa
//
//  Created by liangshangjia on 16/2/17.
//  Copyright © 2016年 Sami-Network. All rights reserved.
//

#import "VCViewModel.h"
#import "Model.h"
@interface VCViewModel ()
@property (nonatomic, strong) RACSignal *arraySignal;
@property (nonatomic, strong) NSArray *fakeArray;
@end

@implementation VCViewModel

- (instancetype)init
{
    if (self = [super init]) {
        [self configure];
    }
    return self;
}

- (void)configure
{
//    _arraySignal = RACObserve(self, self.array);
    _count = 0;
}

//假请求
- (void)request
{
    dispatch_async(dispatch_queue_create("queue", NULL), ^{
        id obj = self.fakeArray[arc4random()%self.fakeArray.count];
        [self.array addObject:obj];
        dispatch_async(dispatch_get_main_queue(), ^{
            self.count = self.array.count;
        });
    });
}


- (NSArray *)fakeArray
{
    if (!_fakeArray) {
        NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"json" ofType:@"json"]];
        _fakeArray = [Model mj_objectArrayWithKeyValuesArray:dict[@"results"]];
    }
    return _fakeArray;
}



- (NSMutableArray *)array
{
    if (!_array) {
        _array = [NSMutableArray arrayWithArray:self.fakeArray];
    }
    return _array;
}
@end
